local skel = fk.CreateSkill {
  name = "emo__shengjian",
}

Fk:loadTranslationTable{
  ["emo__shengjian"] = "圣剑",
  [":emo__shengjian"] = "出牌阶段限一次，你可以选择一名其他角色，手牌数、手牌上限、体力值、体力上限中每有一项你大于其，你对其造成1点伤害，结算后你的对应数值-1。",

  ["#emo__shengjian"] = "圣剑：选择一名其他角色，比较你与其的手牌数、手牌上限、体力值、体力上限",
  ["@@emo__shengjian_damage"] = "伤害%arg",

  ["$emo__shengjian1"] = "圣剑，解放——",
  ["$emo__shengjian2"] = "誓约胜利之剑——！",
}

---@param player Player
---@param to Player
local getWinChoices = function (player, to)
  local choices = {}
  if player.hp > to.hp then table.insert(choices, "hp") end
  if player.maxHp > to.maxHp then table.insert(choices, "maxHp") end
  if player:getHandcardNum() > to:getHandcardNum() then table.insert(choices, "handcardNum") end
  if player:getMaxCards() > to:getMaxCards() then table.insert(choices, "maxCards") end
  return choices
end

skel:addEffect("active", {
  anim_type = "offensive",
  card_num = 0,
  target_num = 1,
  prompt = "#emo__shengjian",
  card_filter = Util.FalseFunc,
  target_tip = function (self, player, to_select, selected, selected_cards, card, selectable, extra_data)
    if selectable then
      local n = #getWinChoices(player, to_select)
      return "@@emo__shengjian_damage:::".. n
    end
  end,
  target_filter = function (self, player, to, selected)
    return #selected == 0 and to and to ~= player
    and #getWinChoices(player, to) > 0
  end,
  times = function (self, player)
    return 1 - player:usedSkillTimes(skel.name, Player.HistoryPhase)
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(skel.name, Player.HistoryPhase) == 0
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local to = effect.tos[1]
    local choices = getWinChoices(player, to)
    if #choices == 0 then return end
    room:delay(#choices * 450)
    room:doIndicate(player, {to})
    room:damage { from = player, to = to, damage = #choices, skillName = skel.name  }
    if player.dead then return end
    if table.contains(choices, "maxCards") then
      room:addPlayerMark(player, MarkEnum.MinusMaxCards)
    end
    if table.contains(choices, "handcardNum") and not player:isKongcheng() then
      if #room:askToDiscard(player, {
        min_num = 1, max_num = 1, include_equip = false, skill_name = skel.name, cancelable = false
      }) == 0 then
        -- 被鸡肋全手牌时强制弃牌
        room:moveCardTo(table.random(player:getCardIds("h")), Card.DiscardPile, nil, fk.ReasonJustMove, skel.name)
      end
    end
    if table.contains(choices, "hp") and not player.dead then
      -- 并非伤害、体流，直接扣体力
      room:changeHp(player, -1, nil, skel.name)
    end
    if table.contains(choices, "maxHp") and not player.dead then
      room:changeMaxHp(player, -1)
    end
  end,
})

return skel
